# 启用测试
enable_testing()

# 查找已编译的gtest库
# find_library(GTEST_LIBRARY gtest HINTS ${CMAKE_BINARY_DIR}/lib)
# find_library(GTEST_MAIN_LIBRARY gtest_main HINTS ${CMAKE_BINARY_DIR}/lib)

# 检查是否找到了库
# if(NOT GTEST_LIBRARY OR NOT GTEST_MAIN_LIBRARY)
#     message(FATAL_ERROR "Could not find gtest libraries in ${CMAKE_BINARY_DIR}/lib")
# endif()

# 创建测试可执行文件
add_executable(os_test
    # 在这里添加测试源文件
    test_thread.cpp
    test_bug_thread.cpp
    test_semaphore.cpp
    test_rw_lock.cpp
    test_main.cpp
)
add_executable(os_memtest
    test_main.cpp
    test_os_memery.cpp
    test_container.cpp
    # test_bug.cpp
)

# 设置可执行文件输出路径为build目录下的bin/test
set_target_properties(os_memtest PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/test
)
# 设置可执行文件输出路径为build目录下的bin/test
set_target_properties(os_test PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/test
)

# 链接库
target_link_libraries(os_test PRIVATE 
    OmniCpp
    gtest
    gtest_main
    pthread
)
# 链接库
target_link_libraries(os_memtest PRIVATE 
    OmniCpp
    gtest
    # gtest_main
    pthread
)

# 添加测试
add_test(NAME os_test COMMAND os_test)

# 设置包含目录
target_include_directories(os_test PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/..
    ${CMAKE_CURRENT_SOURCE_DIR}/../gtest/googletest-release-1.10.0/googletest/include/
    ${CMAKE_CURRENT_SOURCE_DIR}/../gtest/googletest-release-1.10.0/googlemock/include/
)
# 设置包含目录
target_include_directories(os_memtest PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/..
    ${CMAKE_CURRENT_SOURCE_DIR}/../gtest/googletest-release-1.10.0/googletest/include/
    ${CMAKE_CURRENT_SOURCE_DIR}/../gtest/googletest-release-1.10.0/googlemock/include/
)
# 确保 gtest 在 os_test 之前构建
add_dependencies(os_test gtest)
add_dependencies(os_memtest gtest)